package com.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.domain.UserOrder;
import com.example.mapper.UserOrderMapper;
import com.example.service.SysUserService;
import com.example.service.UserOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* @author dlg
* @description 针对表【user_order】的数据库操作Service实现
* @createDate 2024-08-24 16:34:02
*/
@Service
public class UserOrderServiceImpl extends ServiceImpl<UserOrderMapper, UserOrder>
    implements UserOrderService{

    @Autowired
    SysUserService sysUserService;

    /**
     * 回滚机制：
     * 1.异常不能被捕获并处理掉
     * 2.默认运行时异常/Error才会回滚
     */
    @Transactional
    @Override
    public void change() {
        UserOrder userOrder = new UserOrder();
        userOrder.setId(1);
        userOrder.setSale(79);
        baseMapper.updateById(userOrder);
        int i = 1 / 0;
    }

    @Transactional
    @Override
    public void testTranRequired() {
        sysUserService.testTranRequired();
    }

    @Transactional
    @Override
    public void testTranRequiredNew() {
        sysUserService.testTranRequiredNew();
    }

    @Transactional
    @Override
    public void testTranNever() {
        sysUserService.testTranNever();
    }

    @Transactional
    @Override
    public void testTranNested() {
        sysUserService.testTranNested();
        int i = 1 / 0;
    }

    @Transactional
    @Override
    public void testTranNested2() {
        UserOrder userOrder = new UserOrder();
        userOrder.setId(1);
        userOrder.setSale(66);
        baseMapper.updateById(userOrder);

        // 如果该此处异常处理了，testTranNested2的事务不会回滚
        sysUserService.testTranNested2();
    }

    @Override
    public void testTranSupported() {

    }

    @Override
    public void testTranNotSupported() {

    }


    @Override
    public void testTranMandatory() {

    }
}




